<template>
	<view>
		<van-cell-group>
			<van-field :value="formData.title" @input="input($event,'title')" placeholder="请输入标题" required clearable />
			<van-field :value="formData.content" @input="input($event,'content')" placeholder="请输入任务内容" required clearable autosize />
		</van-cell-group>
		<van-goods-action>
			<van-goods-action-button text="提交" type="warning" @click="submit()" />
			<van-goods-action-button text="发布" @click="publishForm()" />
		</van-goods-action>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					title: '',
					content: '',
					status: '',
					teaId: ''
				}
			}
		},
		methods: {
			// 提交 status 0
			// 需要自己实现
			input(event,name) {
				let {
					detail
				} = event;
				this.formData[name] = detail;
			},
			submit() {
				this.formData.status = 0
				this.formData.teaId = uni.getStorageSync('teaId');
				uni.request({
					url: 'http://localhost:8082/task_admin/task/publish',
					data: this.formData,
					method: "POST",
					dataType: "json",
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {
							uni.navigateTo({
								url: '/pages/teacher/task-list'
							});
						}
					}
				});
			},
			// 发布 status 1
			async publishForm() {
				this.formData.status = 1
				this.formData.teaId = uni.getStorageSync('teaId');
				uni.request({
					url: 'http://localhost:8082/task_admin/task/publish',
					data: this.formData,
					method: "POST",
					dataType: "json",
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {
							uni.navigateTo({
								url: '/pages/teacher/task-list'
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
</style>
